﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Daq.Converters
{
    class ColorToBrushConverter : IValueConverter
    {
        public static System.Drawing.Color ConvertToDrawingColor(System.Windows.Media.Color wpfColor)
        {
            return System.Drawing.Color.FromArgb(wpfColor.A, wpfColor.R, wpfColor.G, wpfColor.B);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is DaqColor color)
            {
                return new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B));
            }
            return new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is System.Windows.Media.Color color)
            {
                return new DaqColor(color.R, color.G, color.B, color.A);
            }
            return new DaqColor(255, 0, 0);
        }
    }
}
